applyMiddleware.js ➔ ... ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 1
dl 0
loc 1
rs 10
nop 1
1
export default function applyMiddleware(
2
    applyTo,
3
    middlewares = [],
4
    options = {},
5
    params = {},
6
    resourceId = '',
7
    type = ''
8
) {
9
10
    middlewares = [].concat(middlewares).filter(func => typeof func === 'function');
11
12
    if (!middlewares.length) {
13
        return applyTo(params);
14
    }
15
16
    return middlewares.reduceRight((prev, middleware, index) => {
17
18
        const next = index === middlewares.length - 1
19
            ? prev.bind(null, params)
20
            : prev.bind(null, options, params, resourceId, type);
21
22
        return index === 0
23
            ? middleware(next)(options, params, resourceId, type)
24
            : middleware(next);
25
    }, applyTo);
26
27
}
28